package ua.yandex.threadpool;

import java.util.*;

public class UseThreadPool {

    public static void main(String[] args) {
        Task1 task1 = new Task1();
        Task2 task2 = new Task2();
        Task3 task3 = new Task3();
        int taskCount = 0;
        ThreadPool threadPool = new ThreadPool(2, 2);
        threadPool.go();
        while (taskCount < 30) {
            Random r = new Random();
            int n = r.nextInt(3);
            switch (n) {
                case 0:
                    threadPool.execute(task1);
                case 1:
                    threadPool.execute(task2);
                case 2:
                    threadPool.execute(task3);
                    taskCount++;
                    try {
                        Thread.sleep(50);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
            }
        }
    }
}
